<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends CommonController {
     
     //浏览新闻信息
    public function index(){
       
       $mod = M("news");
       $count = $mod->count();// 查询满足要求的总记录数
       
       $Page = new \Think\PageHome($count,4);// 实例化分页类 传入总记录数和每页显示的记录数(25)

       // $Page -> setConfig('header','共%TOTAL_ROW%条');
       $Page -> setConfig('first','<<');
       // $Page -> setConfig('last','共%TOTAL_PAGE%页');
       $Page -> setConfig('prev','<');
       $Page -> setConfig('next','>');
       $Page -> setConfig('link','indexpagenumb');//pagenumb 会替换成页码
       $Page -> setConfig('theme',' %FIRST% %UP_PAGE% %NOW_PAGE%/%TOTAL_PAGE% 页 %DOWN_PAGE% %END%');
       
       $show = $Page->show();// 分页显示输出
       // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
       $news=M('news')->order('news.addtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();

       //放置模板中
       
       $this->assign("news",$news);
       $this->assign('page',$show);// 赋值分页输出

       //加载模板输出
       $this->assign('title','瞳年资讯');
       $this->display("index");
    }


    //加载编辑表单
    public function detail(){


        $mod =M("news"); 
        $id = I('get.id/d');
        $mod->where('id='.$id)->setInc('click');
        $news = $mod->find($id);
        
        $news['content'] = html_entity_decode($news['content']);
        $prev = $mod->field('id,title')->where('id>'.$id)->order('id asc')->find();
        $next = $mod->field('id,title')->where('id<'.$id)->order('id desc')->find();

        //放置模板中
        $this->assign('keywords',$news['keywords']);
        $this->assign('description',$news['description']);
        $this->assign('title',$news['title'].'　|　瞳年资讯');
        $this->assign("v",$news);
        $this->assign("prev",$prev);
        $this->assign("next",$next);
        //加载编辑模板
        $this->display("detail");
    }

}